package com.example.controller;

import com.example.service.BaseAirLaneService;
import com.example.service.BaseSpecialService;
import com.example.service.BaseTakeoffLandService;
import com.example.service.BaseWorkService;
import com.example.trans.transBaseAirLane;
import com.example.trans.transBaseSpecial;
import com.example.trans.transBaseTakeoffLand;
import com.example.trans.transBaseWork;
import com.example.util.MicroResponseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Optional;

@Deprecated
@Controller
public class BaseController {
    @Autowired
    private BaseAirLaneService baseAirLaneService;
    @Autowired
    private BaseTakeoffLandService baseTakeoffLandService;
    @Autowired
    private BaseWorkService baseWorkService;
    @Autowired
    private BaseSpecialService baseSpecialService;

    @GetMapping("/air/selectall")
    public ResponseEntity getAllUsers() {
        return ResponseEntity.ok(MicroResponseUtils.success(baseAirLaneService.findAll()));
    }
    @GetMapping("/air/select")
    public ResponseEntity findById(@RequestParam Integer id) {
        Optional<transBaseAirLane> user = baseAirLaneService.findByID(id);
        ResponseEntity responseEntity;
        if(user.isPresent()){
            responseEntity = ResponseEntity.ok(MicroResponseUtils.success(user.get()));
        }
        else{
            responseEntity = ResponseEntity.ok(MicroResponseUtils.error("User not found"));
        }
        return responseEntity;
    }
    @PostMapping("/air/create")
    public ResponseEntity createUser(@RequestBody transBaseAirLane user) {
        transBaseAirLane createdUser = baseAirLaneService.isave(user);
        return ResponseEntity.ok(MicroResponseUtils.success(createdUser));
    }
    @PostMapping("/air/update")
    public ResponseEntity updateUser(@RequestBody transBaseAirLane user) {
        Optional<transBaseAirLane> update = baseAirLaneService.update(user);
        if (update.isPresent()) {
            return ResponseEntity.ok(MicroResponseUtils.success(update.get()));
        } else {
            return ResponseEntity.ok(MicroResponseUtils.error("User not found"));
        }
    }
    @PostMapping("/air/delete")
    public ResponseEntity deleteUser(@RequestParam Long id) {
        boolean isDeleted = baseAirLaneService.delete(id);
        return isDeleted ? ResponseEntity.ok(MicroResponseUtils.success("User deleted successfully")) : ResponseEntity.ok(MicroResponseUtils.error("User not found"));
    }


    @GetMapping("/take/selectall")
    public ResponseEntity getAllUsers2() {
        return ResponseEntity.ok(MicroResponseUtils.success(baseTakeoffLandService.findAll()));
    }
    @GetMapping("/take/select")
    public ResponseEntity findById2(@RequestParam Integer id) {
        Optional<transBaseTakeoffLand> user = baseTakeoffLandService.findByID(id);
        ResponseEntity responseEntity;
        if(user.isPresent()){
            responseEntity = ResponseEntity.ok(MicroResponseUtils.success(user.get()));
        }
        else{
            responseEntity = ResponseEntity.ok(MicroResponseUtils.error("User not found"));
        }
        return responseEntity;
    }
    @PostMapping("/take/create")
    public ResponseEntity createUser2(@RequestBody transBaseTakeoffLand user) {
        transBaseTakeoffLand createdUser = baseTakeoffLandService.isave(user);
        return ResponseEntity.ok(MicroResponseUtils.success(createdUser));
    }
    @PostMapping("/take/update")
    public ResponseEntity updateUser2(@RequestBody transBaseTakeoffLand user) {
        Optional<transBaseTakeoffLand> update = baseTakeoffLandService.update(user);
        if (update.isPresent()) {
            return ResponseEntity.ok(MicroResponseUtils.success(update.get()));
        } else {
            return ResponseEntity.ok(MicroResponseUtils.error("User not found"));
        }
    }
    @PostMapping("/take/delete")
    public ResponseEntity deleteUser2(@RequestParam Long id) {
        boolean isDeleted = baseTakeoffLandService.delete(id);
        return isDeleted ? ResponseEntity.ok(MicroResponseUtils.success("User deleted successfully")) : ResponseEntity.ok(MicroResponseUtils.error("User not found"));
    }


    @GetMapping("/work/selectall")
    public ResponseEntity getAllUsers3() {
        return ResponseEntity.ok(MicroResponseUtils.success(baseWorkService.findAll()));
    }
    @GetMapping("/work/select")
    public ResponseEntity findById3(@RequestParam Integer id) {
        Optional<transBaseWork> user = baseWorkService.findByID(id);
        ResponseEntity responseEntity;
        if(user.isPresent()){
            responseEntity = ResponseEntity.ok(MicroResponseUtils.success(user.get()));
        }
        else{
            responseEntity = ResponseEntity.ok(MicroResponseUtils.error("User not found"));
        }
        return responseEntity;
    }
    @PostMapping("/work/create")
    public ResponseEntity createUser3(@RequestBody transBaseWork user) {
        transBaseWork createdUser = baseWorkService.isave(user);
        return ResponseEntity.ok(MicroResponseUtils.success(createdUser));
    }
    @PostMapping("/work/update")
    public ResponseEntity updateUser3(@RequestBody transBaseWork user) {
        Optional<transBaseWork> update = baseWorkService.update(user);
        if (update.isPresent()) {
            return ResponseEntity.ok(MicroResponseUtils.success(update.get()));
        } else {
            return ResponseEntity.ok(MicroResponseUtils.error("User not found"));
        }
    }
    @PostMapping("/work/delete")
    public ResponseEntity deleteUser3(@RequestParam Integer id) {
        boolean isDeleted = baseWorkService.delete(id);
        return isDeleted ? ResponseEntity.ok(MicroResponseUtils.success("User deleted successfully")) : ResponseEntity.ok(MicroResponseUtils.error("User not found"));
    }

    @GetMapping("/special/selectall")
    public ResponseEntity getAllUsers4() {
        return ResponseEntity.ok(MicroResponseUtils.success(baseSpecialService.findAll()));
    }
    @GetMapping("/special/select")
    public ResponseEntity findById4(@RequestParam Integer id) {
        Optional<transBaseSpecial> user = baseSpecialService.findByID(id);
        ResponseEntity responseEntity;
        if(user.isPresent()){
            responseEntity = ResponseEntity.ok(MicroResponseUtils.success(user.get()));
        }
        else{
            responseEntity = ResponseEntity.ok(MicroResponseUtils.error("User not found"));
        }
        return responseEntity;
    }
    @PostMapping("/special/create")
    public ResponseEntity createUser4(@RequestBody transBaseSpecial user) {
        transBaseSpecial createdUser = baseSpecialService.isave(user);
        return ResponseEntity.ok(MicroResponseUtils.success(createdUser));
    }
    @PostMapping("/special/update")
    public ResponseEntity updateUser4(@RequestBody transBaseSpecial user) {
        Optional<transBaseSpecial> update = baseSpecialService.update(user);
        if (update.isPresent()) {
            return ResponseEntity.ok(MicroResponseUtils.success(update.get()));
        } else {
            return ResponseEntity.ok(MicroResponseUtils.error("User not found"));
        }
    }
    @PostMapping("/special/delete")
    public ResponseEntity deleteUser4(@RequestParam Integer id) {
        boolean isDeleted = baseSpecialService.delete(id);
        return isDeleted ? ResponseEntity.ok(MicroResponseUtils.success("User deleted successfully")) : ResponseEntity.ok(MicroResponseUtils.error("User not found"));
    }

}
